/**
 * Created by Administrator on 2017/4/6 0006.
 */
var React = require('react');


var Cheader = require('../widget/Cheader');
var ajax = require('../tools/ajax');
var Photo = require('../widget/Photo');

module.exports = React.createClass({
    getInitialState: function () {
        return {
            theme:"Default", //Default/Blue
            count:50,//初始化字数
            flag: true,
            cancalFlag:true,
            Comment:"",//评论信息
            photoUrl:[],//评论上传图片
            picList:"",
        }
    },

    componentDidMount: function (){

    },
    //照片添加
    picUrl(){
        var p =this;
        var purl = p.refs.Photo.state.photoUrl;
        var url = p.state.photoUrl;
        url.push(purl);
        var i=-1;
        var picList = url.map(function(obj){
            i++;
            return(
                <img key={i} className="photo" src={obj} />
            )
        });
        p.setState({picList:picList,photoUrl:url});
        this.refs.Cheader.setState({photoUrl:url});
    },
    //添加图片界面判断
    photo(){
        this.refs.Photo.setState({flag:this.state.flag});
        var flag = this.state.flag;
        if(flag == false){
            this.setState({flag:true})
        }
    },
    //输入后重新赋值
    change(){
        this.refs.Cheader.setState({comment:this.refs.Comment.value});
    },

    render: function () {
        var p = this;
        return (
            <div className="main"  id="main">
                <Cheader ref="Cheader" lt="取消" rt="发布" title="创建评论" />
                <div className="evaluate-main">
                    <textarea ref="Comment" onChange={p.change} onkeyup={p.checkLen} placeholder="快来分享您的购物点滴吧"  maxLength="200"></textarea>
                    <div className="pic">
                        {p.state.picList}
                        <div className="photo" onClick={p.photo}>+</div>
                    </div>
                </div>
                <Photo ref="Photo" picUrl={p.picUrl}/>
            </div>
        )
    }
});
